
function k() {
    console.log("=1=")
    window.location = '/dev/views/job/page/curriculum.html';

}

// $(function (){
    let userId = localStorage.getItem("id");
    if (userId!=null){
        $.ajax({
            headers:{
                "id":localStorage.getItem("id"),
                "token":localStorage.getItem("token")
            },
            url: `/dev/navUser/${userId}`,
            type: 'GET',
            success:function (result){
                if (result.code==200){
                    console.log(result)
                    console.log(result.data.jsName)

                    $('#username-nav').text(result.data.jsName)
                    $('#username-nav').css('font-weight','bold')
                    $('#username-nav').css('color','#111')
                    let navUser = document.querySelectorAll('.nav-user')[0]
                    navUser.innerHTML += `<img id="user-tx-nav" src="/dev/assets/img/${result.data.avatar}">`

                    layui.use(function(){
                        console.log("====layui====")
                        console.log(layui)
                        var dropdown = layui.dropdown;

                        console.log("==dropdown==")
                        console.log(dropdown)
                        // 自定义事件
                        dropdown.render({
                            elem: '#nav-user',
                            // trigger: 'click' // trigger 已配置在元素 `lay-options` 属性上
                            data: [{
                                // title: 'menu item 1',
                                templet: '<a href="javascript:userInfo();" id="first-nv" style="text-align: center;">个人中心</a>',
                                id: 100
                            },{
                                // title: 'menu item 2',
                                templet: '<a href="javascript:;" id="first-nv" style="text-align: center;">切换为招聘者</a>',
                                id: 101
                            },{
                                // title: 'menu item 3',
                                templet: '<a href="javascript:quit();" id="first-nv" style="text-align: center;">退出登录</a>',
                                id: 102
                            }],
                            style: 'min-width: 100px; padding: 0px; margin: 0px;'
                        });

                    });


                }
            }
        })
    }

    let city = localStorage.getItem("city")
    console.log("=1=city=")
    console.log(city)
    if (city==null){
        let ip = getPublicIP()
        ip.then(resolve =>
            $.ajax({
                headers:{
                    "id":localStorage.getItem("id"),
                    "token":localStorage.getItem("token")
                },
                url: `/dev/city/${resolve}`,
                type: 'POST',
                success: function (result) {
                    // console.log("=2=")
                    if (result.code == 200) {
                        // console.log(result.data)
                        let data = JSON.parse(result.data)
                        // console.log(data.address)
                        let city = data.address.split("|")[2]
                        // console.log(city)
                        localStorage.setItem("city",city)
                        console.log("=city=")
                        console.log(city)
                        $("#city").text(city)
                    }
                }
            })
        )
    }else {
        $("#city").text(city)
    }

// })

function getPublicIP() {
    const apiUrl = "https://api.ipify.org?format=json";
    return new Promise((resolve, reject) => {
            fetch(apiUrl)
                .then(response => response.json())
                .then(data => resolve(data.ip))
                .catch(error => reject(error));
        }
    )
}


function quit() {
    localStorage.removeItem("id");
    localStorage.removeItem("token")
    window.location = '/dev/views/job/page/home.html'
}

function userInfo(){
        window.location='/dev/views/job/page/myuserinfo.html'
}

